<?php
class ymdian_adminControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$this->smarty->assign(array(
			"data"=>M("login")->getymdianadmin()
		));
		$this->smarty->display("ymdian_admin/add.html");
	}
	
	public function onSave(){
		$data['adminname']=$adminname=post('adminname','h');
		
		if(post('password')){
				if(post('password')!=post('password2')) $this->goall("两次密码输入不一致",1);
				$data["salt"]=rand(1000,9999);
				$data["password"]=umd5(post("password","h").$data["salt"]);
				
		}
		
		$data['telephone']=post('telephone');
		$row=M("ymdian_admin")->selectRow("adminname='".$adminname."'");
		
		if($row && $row['adminid']!=$_SESSION['ssymdian_admin']['adminid']){
			$this->goall("账号已经存在",1);
		}
		$salt=rand(1000,9999);
		
		M("ymdian_admin")->update($data,"adminid=".$_SESSION['ssymdianadmin']['adminid']);
		$this->goall("修改成功",0);
	}
}
?>